﻿using Microsoft.EntityFrameworkCore;
using SuYuanRabbit.Domain.Entities.RBAC;
using SuYuanRabbit.Domain.Entities.TraceabilityManagement;
using SuYuanRabbit.Domain.Entities.TraceabilityManagement.FarmingManagement;
using SuYuanRabbit.Domain.Entities.TraceabilityManagement.ProcessingMangement;
using SuYuanRabbit.Domain.Entities.TraceabilityManagement.ProcessingMangement.Vendor;
using SuYuanRabbit.Domain.Entities.TraceabilityManagement.SlaughterManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SuYuanRabbit.Infrastructure.Db
{
    /// <summary>
    /// 数据库上下文
    /// </summary>
    public class MyDbContext : DbContext
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="options">选项</param>
        public MyDbContext(DbContextOptions<MyDbContext> options) : base(options)
        {
        }
        #region RBAC 基于角色的权限控制
        public virtual DbSet<User> Users { get; set; }
        public virtual DbSet<Role> Roles { get; set; }
        public virtual DbSet<RoleUser> RoleUsers { get; set; }
        public virtual DbSet<Permission> Permissions { get; set; }
        public virtual DbSet<RolePermission> RolePermissions { get; set; }
        #endregion

        #region TraceabilityManagement溯源管理
        public virtual DbSet<Shop> Shops { get; set; }
        #region 养殖管理
        public virtual DbSet<DynamicInspectionInformation> DynamicInspectionInformations { get; set; }
        public virtual DbSet<FarmingCompanyInformation> FarmingCompanyInformations { get; set; }
        public virtual DbSet<FarmingInformation> FarmingInformations { get; set; }
        public virtual DbSet<FCompanyImage> FCompanyImages { get; set; }
        public virtual DbSet<ImmunizationInformation> ImmunizationInformations { get; set; }
        #endregion
        #region 屠宰管理
        public virtual DbSet<PCCCascade> PCCCascades { get; set; }
        public virtual DbSet<QualificationInformation> QualificationInformations { get; set; }
        public virtual DbSet<SlaughterCompanyImage> SlaughterCompanyImages { get; set; }
        public virtual DbSet<SlaughterCompanyInformation> SlaughterCompanyInformations { get; set; }
        public virtual DbSet<SlaughterInformation> SlaughterInformations { get; set; }
        #endregion
        #region 深加工管理
        public virtual DbSet<FoodSafetyImage> FoodSafetyImages { get; set; }
        public virtual DbSet<ProcessingInformation> ProcessingInformations { get; set; }
        #region 供应商
        public virtual DbSet<Accessories> Accessories { get; set; }
        public virtual DbSet<AccessoriesImage> AccessoriesImages { get; set; }
        public virtual DbSet<PackagingMaterials> PackagingMaterials { get; set; }
        public virtual DbSet<PackagingMaterialsImage> PackagingMaterialsImages { get; set; }
        public virtual DbSet<RawMaterial> RawMaterials { get; set; }
        public virtual DbSet<RawMaterialImage> RawMaterialImages { get; set; }
        public virtual DbSet<VendorCompany> VendorCompanies { get; set; }
        public virtual DbSet<VendorCompanyImage> VendorCompanyImages { get; set; }
        #endregion
        #endregion
        #endregion

        //配置主键
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<User>(entity =>
            {
                entity.HasKey(x => x.UserId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Role>(entity =>
            {
                entity.HasKey(x => x.RoleId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<RoleUser>(entity =>
            {
                entity.HasKey(x => x.RoleUserId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Permission>(entity =>
            {
                entity.HasKey(x => x.PermissionId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<RolePermission>(entity =>
            {
                entity.HasKey(x => x.RolePermissionId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Shop>(entity =>
            {
                entity.HasKey(x => x.ShopId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<DynamicInspectionInformation>(entity =>
            {
                entity.HasKey(x => x.DynamicInspectionId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<FarmingCompanyInformation>(entity =>
            {
                entity.HasKey(x => x.FCompanyId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<FarmingInformation>(entity =>
            {
                entity.HasKey(x => x.FarmingId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<FCompanyImage>(entity =>
            {
                entity.HasKey(x => x.FCImageId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<ImmunizationInformation>(entity =>
            {
                entity.HasKey(x => x.ImmunizationId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<PCCCascade>(entity =>
            {
                entity.HasKey(x => x.CascadeId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<QualificationInformation>(entity =>
            {
                entity.HasKey(x => x.QualificationId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<SlaughterCompanyImage>(entity =>
            {
                entity.HasKey(x => x.SCImageId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<SlaughterCompanyInformation>(entity =>
            {
                entity.HasKey(x => x.SCompanyId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<SlaughterInformation>(entity =>
            {
                entity.HasKey(x => x.SlaughterId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<FoodSafetyImage>(entity =>
            {
                entity.HasKey(x => x.FImageId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<ProcessingInformation>(entity =>
            {
                entity.HasKey(x => x.ProcessingId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Accessories>(entity =>
            {
                entity.HasKey(x => x.AccessoriesId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<AccessoriesImage>(entity =>
            {
                entity.HasKey(x => x.AccessoriesImageId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<PackagingMaterials>(entity =>
            {
                entity.HasKey(x => x.PackagingMaterialsId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<PackagingMaterialsImage>(entity =>
            {
                entity.HasKey(x => x.PMaterialsImageId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<RawMaterial>(entity =>
            {
                entity.HasKey(x => x.RawMaterialId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<RawMaterialImage>(entity =>
            {
                entity.HasKey(x => x.RMaterialImageId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<VendorCompany>(entity =>
            {
                entity.HasKey(x => x.VCompanyId);
            });
            base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<VendorCompanyImage>(entity =>
            {
                entity.HasKey(x => x.VCompanyImageId);
            });
        }
    }
}
